using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Tomahawk.Runtime.Input
{
    //events when all patterns have been tested in this player
    public delegate void BeforePlayerPadUpdate(GamePadState state);
    public delegate void AfterPlayerPadUpdate(GamePadState state);

    public class GamePadManager
    {
        #region "Private members: index, state, patterns, events"

        private PlayerIndex index;
        private GamePadState state;
        
        private Pattern.GamePadPatterns patterns;
        
        public event BeforePlayerPadUpdate OnBeforePlayerPadUpdate;
        public event AfterPlayerPadUpdate OnAfterPlayerPadUpdate;

        #endregion

        #region "Getters & setters"

        public GamePadState State { get { return state; } }
        public PlayerIndex Index { get { return index; } }
        public Pattern.GamePadPatterns Patterns{ get { return patterns;} }

        #endregion

        public GamePadManager(PlayerIndex playerIndex) 
        {
            this.index = playerIndex;
            patterns = new Pattern.GamePadPatterns();
        }

        public void Update(float elapsedTime)
        {
            state = GamePad.GetState(index, GamePadDeadZone.IndependentAxes);

            if (OnBeforePlayerPadUpdate != null) OnBeforePlayerPadUpdate(state);

            #region "Update player stuff"
            
            //other update stuff

            patterns.Match(state, elapsedTime);
            
            #endregion

            if (OnAfterPlayerPadUpdate != null) OnAfterPlayerPadUpdate(state);
        }

    }

}


